//
//  HMMainTabbarController.swift
//  Weibo
//
//  Created by 京城 on 16/7/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMMainTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
       addChildViewController()
        
        let mainTabBar = HMtabBarView()
        self.setValue(mainTabBar, forKey: "tabBar")
        mainTabBar.callback = {
            
        //模态出控制器
            
            
        }
        
    }
    
    func addChildViewController(){
        
        let homeVC = HMHomeTableViewController()
        addChildViewController(homeVC, title: "主页", imageName: "tabbar_home")
        
        let messageVC = HMMessageTableViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let discoveryVC = HMDiscoveryTableViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        
        let profileVC = HMProfileTableViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    
    
    func addChildViewController(controller:UIViewController,title:String,imageName:String){
        controller.title = title
        
        //controller.tabBarItem.title = title
        controller.tabBarItem.image = UIImage(named: imageName)

        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        let selectedImageName = imageName + "_selected"
        controller.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self .addChildViewController(UINavigationController(rootViewController: controller))
      
        
    }

   
}
